package com.oscar.ehome.view.konwledge;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.base.fragment.BaseFragment;
import com.oscar.ehome.bean.loginbean.UserBean;
import com.oscar.ehome.bean.pagebean.ClassRoomBean;
import com.oscar.ehome.bean.pagebean.ClassRoomPrombleBean;
import com.oscar.ehome.presenter.BasePresenter;
import com.oscar.ehome.presenter.KnowelgePresenter;
import com.oscar.ehome.provider.gildeimage.GildeUtils;
import com.oscar.ehome.utils.basethem.TintManager;
import com.oscar.ehome.utils.system.SystemConfigFactory;
import com.oscar.ehome.utils.util.ToastUtil;
import com.oscar.ehome.utils.view.MyImageView;
import com.oscar.ehome.view.konwledge.view.KnowsetView;
import com.oscar.ehome.view.loginview.LoginActivity;
import com.oscar.ehome.view.pageview.BannerWebActivity;
import com.oscar.ehome.view.setview.FeedBackActivity;
import com.oscar.ehome.view.setview.SettingActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/9/20
 * 律师团队设置页
 */

public class KonwSetFragment extends BaseFragment implements KnowsetView {

    public View view;
    Unbinder unbinder;

    /**
     *
     */
    @BindView(R.id.title_topbar)
    TextView titleTopbar;
    /**
     *
     */
    @BindView(R.id.basetitle_bar)
    RelativeLayout basetitleBar;
    /**
     *
     */
    @BindView(R.id.know_head)
    MyImageView knowHead;
    /**
     *
     */
    @BindView(R.id.know_name)
    TextView knowName;
    /**
     *
     */
    @BindView(R.id.know_leve)
    TextView knowLeve;
    /**
     *
     */
    @BindView(R.id.sex_img)
    ImageView sexImg;
    /**
     *
     */
    @BindView(R.id.knowgonghao)
    TextView knowgonghao;
    /**
     *
     */
    @BindView(R.id.knowset_layout)
    RelativeLayout knowsetLayout;
    /**
     *
     */
    @BindView(R.id.knowpromble_advise)
    LinearLayout knowprombleAdvise;
    /**
     *
     */
    @BindView(R.id.knowyijian_advise)
    LinearLayout knowyijianAdvise;
    /**
     *
     */
    @BindView(R.id.liear_knowshow)
    LinearLayout liearKnowshow;
    /**
     *
     */
    @BindView(R.id.liear_knowsetting)
    LinearLayout liearKnowsetting;
    /**
     *
     */
    @BindView(R.id.knowlearn_img)
    ImageView knowlearnImg;
    /**
     *
     */
    @BindView(R.id.knowpromble_img)
    ImageView knowprombleImg;
    /**
     *
     */
    @BindView(R.id.knowyijian_img)
    ImageView knowyijianImg;
    /**
     *
     */
    @BindView(R.id.knowshuoming_img)
    ImageView knowshuomingImg;
    /**
     *
     */
    @BindView(R.id.knowshehzhi_img)
    ImageView knowshehzhiImg;

    UserBean userBean;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_knowset, null);
        unbinder = ButterKnife.bind(this, view);
        setColor();
        init();
        return view;
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    /**
     * 改变颜色
     */
    public void setColor() {
        TintManager.setTint(knowlearnImg, Color.parseColor(SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getColor()));
        TintManager.setTint(knowprombleImg, Color.parseColor(SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getColor()));
        TintManager.setTint(knowyijianImg, Color.parseColor(SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getColor()));
        TintManager.setTint(knowshuomingImg, Color.parseColor(SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getColor()));
        TintManager.setTint(knowshehzhiImg, Color.parseColor(SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getColor()));
        basetitleBar.setBackgroundColor(Color.parseColor(SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getColor()));
        knowsetLayout.setBackgroundColor(Color.parseColor(SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getColor()));
    }

    public void init() {
        String user = SystemConfigFactory.getInstance(getActivity()).getSystemConfig().getUserBean();
        userBean = new Gson().fromJson(user, UserBean.class);
        if (userBean != null) {
            if (userBean.getPhoto() != null) {
                GildeUtils.loadUrlImage4(C.qiniu_ip + userBean.getPhoto(), knowHead, getActivity());
            }
            if (userBean.getName() != null) {
                knowName.setText(userBean.getName());
            }
        }
    }


    @OnClick({R.id.knowset_layout, R.id.liear_know, R.id.knowpromble_advise, R.id.knowyijian_advise, R.id.liear_knowshow, R.id.liear_knowsetting})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.knowset_layout:
                break;
            case R.id.liear_know://学习资料
                startActivity(new Intent(getActivity(), MyStudyListActivity.class));
                break;
            case R.id.knowpromble_advise://我的问题
                startActivity(new Intent(getActivity(), MyPrombleListActivity.class));
                break;
            case R.id.knowyijian_advise://意见反馈
                startActivity(new Intent(getActivity(), FeedBackActivity.class));
                break;
            case R.id.liear_knowshow://说明文档
                Intent intent_about = new Intent(getActivity(), BannerWebActivity.class);
                intent_about.putExtra("contentsrc", C.shuoming_url);
                intent_about.putExtra("type", "shuoming");
                intent_about.putExtra("name", "");
                intent_about.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent_about);
                break;
            case R.id.liear_knowsetting://设置
                Intent intentset = new Intent(getActivity(), SettingActivity.class);
                startActivity(intentset);
                break;
        }
    }


    @Override
    public void myPrombleList(ClassRoomPrombleBean bean) {

    }

    @Override
    public void erroy() {
        dismissLoading();
        ToastUtil.show(getActivity(), getString(R.string.erry));
    }

    @Override
    public void erry(String result) {
        dismissLoading();
        ToastUtil.show(getActivity(), result);
        if (result.contains("过期")) {
            getActivity().getSharedPreferences("appbase", getActivity().MODE_PRIVATE).edit().clear().commit();
            SystemConfigFactory.getInstance(getActivity()).getSystemConfig().SetLogin(false);
            SystemConfigFactory.getInstance(getActivity()).getSystemConfig().setIsFirst(true);
            Intent intent = new Intent(getActivity(), LoginActivity.class);
            startActivity(intent);
            getActivity().finish();
        }
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

}
